package com.bms.entity;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

/**
 * 待审核的应用模块
 * @author Lan
 */
@Entity
@Table(name = "T_APP")
@JsonIgnoreProperties (value = { "hibernateLazyInitializer", "roleSet" })
public class App extends BaseEntity {

	private static final long serialVersionUID = 5511345133923876976L;

	private String englishName;//TQ/WJ/ZS
	private String identity;//TodayWeather/PriceOfThings/LifeIndex
	private String chineseName;
	private Boolean isAutoPub;
	
	private Set<Role> roleSet;//一个应用可有多个"审核级别"
	
	private String downMsg;
	private String publishMsg;

	//临时属性
	private String auditMsg;//本次审核不通过的原因
	private String lastAuditMsg;//上一级审核不通过的原因
	private Long newFileNum;
	private Long auditFileNum;
	private Long pubFileNum;

	public App() {
	}

	public App(String englishName, String identity, String chineseName, Boolean isAutoPub) {
		this.englishName = englishName;
		this.identity = identity;
		this.chineseName = chineseName;
		this.isAutoPub = isAutoPub;
	}

	/**
	 * @return 英文名：TQ/WJ/ZS
	 * @author Lan
	 */
	@Column(updatable = false, unique = true, length = 20)
	public String getEnglishName() {
		return englishName;
	}

	/**
	 * @param englishName 英文名：TQ/WJ/ZS
	 * @author Lan
	 */
	public void setEnglishName(String englishName) {
		this.englishName = englishName;
	}

	/**
	 * @return 中文名称
	 * @author Lan
	 */
	@Column(updatable = false, unique = true, length = 50)
	public String getChineseName() {
		return chineseName;
	}

	/**
	 * @param chineseName 中文名称
	 * @author Lan
	 */
	public void setChineseName(String chineseName) {
		this.chineseName = chineseName;
	}

	/**
	 * 应用标识
	 * @return
	 * @author Lan
	 */
	@Column(updatable = false, unique = true, length = 50)
	public String getIdentity() {
		return identity;
	}

	public void setIdentity(String identity) {
		this.identity = identity;
	}

	/**
	 * 是否自动审核发布
	 * 
	 * @author Lan
	 * @return true-自动, false-手动
	 */
	@Column
	public Boolean getIsAutoPub() {
		return isAutoPub;
	}

	/**
	 * 设置是否自动审核发布
	 * 
	 * @author Lan
	 * @param isAutoPub
	 *            true-自动, false-手动
	 */
	public void setIsAutoPub(Boolean isAutoPub) {
		this.isAutoPub = isAutoPub;
	}

	/**
	 * 
	 * @author Lan
	 * @return
	 */
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name="T_AUDIT_RESULT", joinColumns=@JoinColumn(name="app_id"), inverseJoinColumns=@JoinColumn(name="role_id"))
	public Set<Role> getRoleSet() {
		return roleSet;
	}

	public void setRoleSet(Set<Role> roleSet) {
		this.roleSet = roleSet;
	}

	/**
	 * 记录FTP下载新文件过程中的错误信息
	 * @author Lan
	 * @return
	 */
	@Column(length = 1000)
	public String getDownMsg() {
		return downMsg;
	}

	/**
	 * 记录FTP下载新文件过程中的错误信息
	 * @author Lan
	 * @param downMsg
	 */
	public void setDownMsg(String downMsg) {
		this.downMsg = downMsg;
	}

	/**
	 * @author Lan
	 * @return 记录发布后的信息
	 */
	@Column(length = 1000)
	public String getPublishMsg() {
		return publishMsg;
	}

	/**
	 * @author Lan
	 * @param publishMsg
	 *            记录发布后的信息
	 */
	public void setPublishMsg(String publishMsg) {
		this.publishMsg = publishMsg;
	}

	/**
	 * 本次审核不通过的原因
	 * @author Lan
	 * @return
	 */
	@Transient
	public String getAuditMsg() {
		return auditMsg;
	}

	/**
	 * 本次审核不通过的原因
	 * @author Lan
	 * @param auditMsg
	 */
	public void setAuditMsg(String auditMsg) {
		this.auditMsg = auditMsg;
	}
	
	/**
	 * 上次审核不通过的原因
	 * @author Lan
	 * @return
	 */
	@Transient
	public String getLastAuditMsg() {
		return lastAuditMsg;
	}

	/**
	 * 上次审核不通过的原因
	 * @author Lan
	 * @param lastAuditMsg
	 */
	public void setLastAuditMsg(String lastAuditMsg) {
		this.lastAuditMsg = lastAuditMsg;
	}

	/**
	 * @return the newFileNum
	 */
	@Transient
	public Long getNewFileNum() {
		return newFileNum;
	}

	/**
	 * @param newFileNum
	 *            the newFileNum to set
	 */
	public void setNewFileNum(Long newFileNum) {
		this.newFileNum = newFileNum;
	}

	/**
	 * @return the auditFileNum
	 */
	@Transient
	public Long getAuditFileNum() {
		return auditFileNum;
	}

	/**
	 * @param auditFileNum
	 *            the auditFileNum to set
	 */
	public void setAuditFileNum(Long auditFileNum) {
		this.auditFileNum = auditFileNum;
	}

	/**
	 * @return the pubFileNum
	 */
	@Transient
	public Long getPubFileNum() {
		return pubFileNum;
	}

	/**
	 * @param pubFileNum
	 *            the pubFileNum to set
	 */
	public void setPubFileNum(Long pubFileNum) {
		this.pubFileNum = pubFileNum;
	}

	@Override
	public String toString() {
		return this.englishName + "/" + this.chineseName + "/" + this.identity + "/" + this.isAutoPub;
	}

}
